<script setup lang="ts">
import { computed } from "vue";
import { RouteLocationRaw, useRoute } from "vue-router";
import { TinyColor } from "utils/index";
const { pioneer, i } = defineProps<{
  pioneer: {
    avatar: string;
    name: string;
    to: RouteLocationRaw | string;
  };
  i?: number;
}>();
const defaultAvatar =
  "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png";
const route = useRoute();
const onActive = computed(() => String(route.matched[1]?.name) === pioneer.to);
const linearColor = TinyColor(i);
const linearColorTo = TinyColor(Number(i) + 20);
</script>

<template>
  <router-link
    :to="{name:pioneer.name}"
    class="pioneer-item cursor-pointer ml-2 mr-2.5 p-0.5 max-h-12"
    :class="{ onActive }"
  >
    <div class="pioneer-item-wrapper box-border p-0.5 w-40 h-full flex">
      <div class="link-left">
        <img
          class="link-img bg-slate-50"
          :src="pioneer.avatar || defaultAvatar"
        />
      </div>
      <div class="link-info flex-auto flex  justify-center">
        <span class="link-name flex items-center">{{ pioneer.name }}</span>
      </div>
    </div>
  </router-link>
</template>

<style lang="less" scoped>
.pioneer-item {
  &:hover,
  &.onActive {
    .pioneer-item-wrapper {
      color: white;
      backdrop-filter: saturate(50%) blur(4px);
      background-image: linear-gradient(
        to bottom right,
        v-bind("linearColor"),
        v-bind("linearColorTo")
      );
    }
  }
  .pioneer-item-wrapper {
    border-radius: 999px;
    transition: all 0.2s;
  }
}
.link-left {
  aspect-ratio: 1;
  .link-img {
    border-radius: 50%;
    border: var(--vast-default-border);
    width: 100%;
    height: 100%;
  }
}
.link-info {
  .link-name {
    font-size: 1.25rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}
</style>
